package org.example.freemarker;

import freemarker.template.TemplateExceptionHandler;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;

import java.io.IOException;

/**
 * @author weigang
 * @create 2022-10-27 17:36
 */

@Configuration
public class FreemarkerConfig {
    private String templatePath = "/templates";

    @Bean(name = "wgFreemarkerConfig")
    public freemarker.template.Configuration wgFreemarkerConfig() throws IOException {
        freemarker.template.Configuration cfg =
                new freemarker.template.Configuration(freemarker.template.Configuration.VERSION_2_3_22);
        cfg.setClassForTemplateLoading(this.getClass(), templatePath);
        cfg.setDefaultEncoding("UTF-8");
        cfg.setTemplateExceptionHandler(TemplateExceptionHandler.RETHROW_HANDLER);
        return cfg;
    }
}
